package com.medicine.hbp.adapter;

import org.kymjs.kjframe.KJBitmap;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.medicine.hbp.R;
import com.medicine.hbp.base.MyBaseAdapter;
import com.medicine.hbp.mob.findIntegralActivityVo;
import com.medicine.hbp.sp.LoginSp;
import com.medicine.hbp.ui.BannerWebActivity;
import com.medicine.hbp.ui.IntegralActivity;
import com.medicine.hbp.uitl.StartIntent;

public class IntegralAdapter extends MyBaseAdapter{
	private LayoutInflater inflater;
	KJBitmap bitmap=new KJBitmap();
	public IntegralAdapter(Activity activity) {
		this.activity=activity;
		inflater = LayoutInflater.from(activity);
	}
	@Override
	public View getView(int position, View view, ViewGroup arg2) {
		ViewHolder holder;
		if (view == null) {
			holder = new ViewHolder();
			view = inflater.inflate(R.layout.item_integral, null);
			holder.img_integral=(ImageView) view.findViewById(R.id.img_integral);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		final findIntegralActivityVo vo=(findIntegralActivityVo) getItem(position);
		if(vo!=null){
			bitmap.display(holder.img_integral, vo.intgActivityImgUrl);
			holder.img_integral.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
				}
			});
			holder.img_integral.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					if(TextUtils.isEmpty(LoginSp.getToken(activity))){
						StartIntent.startLogin(activity);
					}else{
						Intent intent=new Intent(activity,BannerWebActivity.class);
						if(TextUtils.isEmpty(LoginSp.getToken(activity))){
							intent.putExtra("URL",vo.intgActivityUrl);
						}else{
							intent.putExtra("URL",vo.intgActivityUrl+"&token="+ LoginSp.getToken(activity));
						}
						intent.putExtra("NAME","积分活动");
						activity.startActivity(intent);
					}

				}
			});
		}

		return view;
	}
	class ViewHolder {
		ImageView img_integral;
	}
}
